<template>
  <view class="page">
    <!-- 头部导航 -->
    <view class="header">
      <view class="header-content">
        <view class="left-section" @tap="goBack">
          <image
            src="/static/icons/left_arrow.png"
            class="back-icon"
            mode="aspectFit"
          ></image>
        </view>
        <text class="header-title">个人签名</text>
        <view class="right-section" @tap="saveSignature">
          <text class="save-btn">保存</text>
        </view>
      </view>
    </view>

    <!-- 内容区域 -->
    <view class="content">
      <!-- 标题和描述 -->
      <view class="title-section">
        <text class="main-title">编辑签名</text>
        <text class="description">一个好签名可以吸引更优秀的人才~</text>
      </view>

      <!-- 签名输入区域 -->
      <view class="input-section">
        <textarea
          v-model="signatureText"
          class="signature-input"
          placeholder="请填写你的签名~"
          placeholder-class="placeholder-text"
          maxlength="200"
          auto-height
        ></textarea>
        <view class="char-count">{{ signatureText.length }}/200</view>
      </view>

      <!-- 求职者关注点提示 -->
      <view class="tips-section">
        <text class="tips-title">求职者都关注这些:</text>
        <view class="tips-list">
          <view class="tip-item">
            <text class="tip-dot">•</text>
            <text class="tip-text">团队氛围</text>
          </view>
          <view class="tip-item">
            <text class="tip-dot">•</text>
            <text class="tip-text">发展前景</text>
          </view>
          <view class="tip-item">
            <text class="tip-dot">•</text>
            <text class="tip-text">管理风格</text>
          </view>
          <view class="tip-item">
            <text class="tip-dot">•</text>
            <text class="tip-text">福利待遇</text>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { getHrInfoApi, updateCompanyUserBindInfoApi } from '@/api/user.js'

// 签名文本
const signatureText = ref('')

// 获取HR信息
const getHrInfo = async () => {
  try {
    const response = await getHrInfoApi()
    if (response && response.hrSignature) {
      signatureText.value = response.hrSignature
    }
  } catch (error) {
    console.error('获取HR信息失败:', error)
  }
}

// 返回上一页
const goBack = () => {
  uni.navigateBack()
}

// 保存签名
const saveSignature = async () => {
  if (!signatureText.value.trim()) {
    uni.showToast({
      title: '请输入签名内容',
      icon: 'none'
    })
    return
  }

  try {
    // 调用保存签名的API
    await updateCompanyUserBindInfoApi({
      hrSignature: signatureText.value.trim()
    })
    
    uni.showToast({
      title: '保存成功',
      icon: 'success'
    })
    
    // 延迟返回，让用户看到成功提示
    setTimeout(() => {
      // 发送事件通知上一页需要刷新数据
      uni.$emit('refreshHrInfo')
      uni.navigateBack()
    }, 1000)
  } catch (error) {
    console.error('保存签名失败:', error)
    uni.showToast({
      title: '保存失败',
      icon: 'none'
    })
  }
}

onMounted(() => {
  getHrInfo()
})
</script>

<style lang="scss" scoped>
.page {
  min-height: 100vh;
  background-color: #ffffff;
}

/* 头部导航 */
.header {
  background-color: #00bdb4;
  padding-top: var(--status-bar-height);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30rpx;
  height: 88rpx;
  position: relative;
}

.left-section {
  display: flex;
  align-items: center;
  min-width: 80rpx;
  padding: 20rpx 0;
}

.back-icon {
  width: 48rpx;
  height: 48rpx;
}

.header-title {
  font-size: 36rpx;
  font-weight: 500;
  color: #ffffff;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.right-section {
  display: flex;
  align-items: center;
  min-width: 80rpx;
  padding: 20rpx 0;
}

.save-btn {
  font-size: 32rpx;
  color: #ffffff;
  font-weight: 500;
}

/* 内容区域 */
.content {
  padding: 40rpx 30rpx;
}

/* 标题和描述 */
.title-section {
  margin-bottom: 40rpx;
}

.main-title {
  font-size: 48rpx;
  font-weight: bold;
  color: #111827;
  display: block;
  margin-bottom: 16rpx;
}

.description {
  font-size: 28rpx;
  color: #6b7280;
  display: block;
}

/* 签名输入区域 */
.input-section {
  margin-bottom: 60rpx;
  position: relative;
}

.signature-input {
  width: 100%;
  min-height: 200rpx;
  background-color: #f8f8f8;
  border-radius: 16rpx;
  padding: 24rpx;
  font-size: 32rpx;
  color: #111827;
  line-height: 1.5;
  box-sizing: border-box;
}

.placeholder-text {
  color: #9ca3af;
  font-size: 32rpx;
}

.char-count {
  position: absolute;
  bottom: 16rpx;
  right: 24rpx;
  font-size: 24rpx;
  color: #9ca3af;
}

/* 求职者关注点提示 */
.tips-section {
  padding: 32rpx 0;
}

.tips-title {
  font-size: 28rpx;
  color: #374151;
  font-weight: 500;
  display: block;
  margin-bottom: 24rpx;
}

.tips-list {
  display: flex;
  flex-direction: column;
  gap: 16rpx;
}

.tip-item {
  display: flex;
  align-items: center;
}

.tip-dot {
  font-size: 24rpx;
  color: #6b7280;
  margin-right: 16rpx;
  font-weight: bold;
}

.tip-text {
  font-size: 28rpx;
  color: #6b7280;
}

/* 响应式设计 */
@media (max-width: 750rpx) {
  .content {
    padding: 30rpx 20rpx;
  }
  
  .main-title {
    font-size: 40rpx;
  }
  
  .signature-input {
    min-height: 160rpx;
    padding: 20rpx;
  }
}
</style>
